package com.mall.goods.common.config;

import io.micrometer.common.util.StringUtils;

import java.util.Random;

/**

 *
 * 全局配置文件
 *
 * @author
 * Created 2017/4/17 10:55
 */
public class ShopConfig {
    /**
     * 主域名
     */
    private static String host;

    /**
     * api域名
     */
    private static String apiRoot;

    /**
     * web域名
     */
    private static String webRoot;

    /**
     * admin域名
     */
    private static String adminRoot;

    /**
     * member域名
     */
    private static String memberRoot;

    /**
     * seller域名
     */
    private static String sellerRoot;

    /**
     * chain域名
     */
    private static String chainRoot;

    /**
     * apiSeller域名
     */
    private static String apiSellerRoot;

    /**
     * wap域名
     */
    private static String wapRoot;

    /**
     * 上传域名
     */
    private static String uploadRoot;

    /**
     * 上传域名组
     */
    private static String uploadGroup;

    private static String[] uploadArray;

    private static int uploadArrayLength;

    /**
     * 公共文件域名
     */
    private static String publicRoot;

    /**
     * 默认分页数
     */
    private static int pageSize = 20;

    /**
     * 是否https
     */
    private static boolean isHttps = false;

    /**
     * 是否开启缓存
     */
    private static boolean cacheEnable = false;
    /**
     * 高德地图key
     */
    private static String amapKey;

    public static String getHost() {
        return host;
    }

    public static void setHost(String host) {
        ShopConfig.host = host;
    }

    public static String getApiRoot() {
        return apiRoot;
    }

    public static void setApiRoot(String apiRoot) {
        ShopConfig.apiRoot = apiRoot;
    }

    public static String getWebRoot() {
        return webRoot;
    }

    public static void setWebRoot(String webRoot) {
        ShopConfig.webRoot = webRoot;
    }

    public static String getAdminRoot() {
        return adminRoot;
    }

    public static void setAdminRoot(String adminRoot) {
        ShopConfig.adminRoot = adminRoot;
    }

    public static String getMemberRoot() {
        return memberRoot;
    }

    public static void setMemberRoot(String memberRoot) {
        ShopConfig.memberRoot = memberRoot;
    }

    public static String getSellerRoot() {
        return sellerRoot;
    }

    public static void setSellerRoot(String sellerRoot) {
        ShopConfig.sellerRoot = sellerRoot;
    }

    public static String getChainRoot() {
        return chainRoot;
    }

    public static void setChainRoot(String chainRoot) {
        ShopConfig.chainRoot = chainRoot;
    }

    public static String getApiSellerRoot() {
        return apiSellerRoot;
    }

    public static void setApiSellerRoot(String apiSellerRoot) {
        ShopConfig.apiSellerRoot = apiSellerRoot;
    }

    public static String getWapRoot() {
        return wapRoot;
    }

    public static void setWapRoot(String wapRoot) {
        ShopConfig.wapRoot = wapRoot;
    }

    public static String getUploadRoot() {
        if(uploadArrayLength > 0) {
            int rnd = new Random().nextInt(uploadArrayLength);
            return uploadArray[rnd];
        } else {
            return StringUtils.isBlank(uploadRoot) ? "https://example.com/upload/" : uploadRoot;
        }
    }

    public static void setUploadRoot(String uploadRoot) {
        ShopConfig.uploadRoot = uploadRoot;
    }

    public static String getUploadGroup() {
        return uploadGroup;
    }

    public static void setUploadGroup(String uploadGroup) {
        if(!StringUtils.isBlank(uploadGroup)) {
            ShopConfig.uploadArray = uploadGroup.split(",");
            ShopConfig.uploadArrayLength = ShopConfig.uploadArray.length;
        } else {
            ShopConfig.uploadArrayLength = 0;
        }
        ShopConfig.uploadGroup = uploadGroup;
    }

    // 添加配置检查和默认值
    public static String getPublicRoot() {
        return StringUtils.isBlank(publicRoot) ? "https://example.com/public/" : publicRoot;
    }

    public static void setPublicRoot(String publicRoot) {
        ShopConfig.publicRoot = publicRoot;
    }

    public static int getPageSize() {
        return pageSize;
    }

    public static void setPageSize(int pageSize) {
        ShopConfig.pageSize = pageSize;
    }

    public static boolean isHttps() {
        return isHttps;
    }

    public static void setIsHttps(boolean isHttps) {
        ShopConfig.isHttps = isHttps;
    }

    public static boolean isCacheEnable() {
        return cacheEnable;
    }

    public static void setCacheEnable(boolean cacheEnable) {
        ShopConfig.cacheEnable = cacheEnable;
    }

    public static String getAmapKey() {
        return amapKey;
    }

    public static void setAmapKey(String amapKey) {
        ShopConfig.amapKey = amapKey;
    }
}
